/**
 * 
 */
package com.nwpusp.model.session;

import com.nwpusp.transmitter.Transmitter;


/**
 * @author JustinCao
 *
 */
public class ListenSession extends Session {
	private int supportNum = 0;
	
	public ListenSession(ConnectionId cid, Transmitter trans) {
		super(cid, trans);
	}

	public void Listen(int supportNum) {
		if(trans != null) {
			setSupportNum(supportNum);
			trans.Listen(getConnectionId());
		}
	}
	
	synchronized public void setSupportNum(int supportNum) {
		this.supportNum = supportNum;
	}
	
	synchronized public boolean Accept(ConnectionId client) {
		if(supportNum > 0) {
			supportNum--;
			return true;
		}
		return false;
	}

	synchronized public void clientLeave() {
		supportNum++;
	}
}
